The File Manager provides the FSpOpenDF , FSpCreate , and FSpDelete routines, which allow you to open, create, and delete files.
You can use the FSpOpenDF function to open a file's data fork.
FUNCTION FSpOpenDF (spec: FSSpec; permission: SignedByte;
VAR refNum: Integer): OSErr;
The FSpOpenDF function opens the data fork of the file specified by the spec parameter and returns a file reference number in the refNum parameter. You can pass that reference number as a parameter to any of the low- or high-level file access routines.
The permission parameter specifies the kind of access permission mode you want. You can specify one of these constants:
CONST
fsCurPerm = 0; {whatever permission is allowed}
fsRdPerm = 1; {read permission}
fsWrPerm = 2; {write permission}
fsRdWrPerm = 3; {exclusive read/write permission}
fsRdWrShPerm = 4; {shared read/write permission}
In most cases, you can simply set the permission parameter to fsCurPerm . Some applications request fsRdWrPerm , to ensure that they can both read from and write to a file.
You can use the FSpCreate function to create a new file.
FUNCTION FSpCreate (spec: FSSpec; creator: OSType;
fileType: OSType; scriptTag: ScriptCode):
OSErr;
The FSpCreate function creates a new file (both forks) with the specified type, creator, and script code. The new file is unlocked and empty. The date and time of creation and last modification are set to the current date and time.
See the chapter "Finder Interface" in Inside Macintosh: Macintosh Toolbox Essentials for information on file types and creators.
Files created using FSpCreate are not automatically opened. If you want to write data to the new file, you must first open the file using a file access routine (such as FSpOpenDF).
The resource fork of the new file exists but is empty. You'll need to call one of the Resource Manager procedures CreateResFile , HCreateResFile , or FSpCreateResFile to create a resource map in the file before you can open it (by calling one of the Resource Manager functions OpenResFile , HOpenResFile , or FSpOpenResFile ).
You can use the FSpDelete function to delete files and directories.
FUNCTION FSpDelete (spec: FSSpec): OSErr;
The FSpDelete function removes a file or directory. If the specified target is a file, both forks of the file are deleted. The file ID reference, if any, is removed.
A file must be closed before you can delete it. Similarly, a directory must be empty before you can delete it. If you attempt to delete an open file or a nonempty directory, FSpDelete returns the result code fBsyErr . FSpDelete also returns the result code fBsyErr if the directory has an open working directory associated with it.